import absanimateengine from "./absanimateengine";
import rotategraphsvc from "../service/rotategraphsvc";
import utilfuncs from "../common/tools/utilfuncs";
var funcs = utilfuncs.UtilFuncs;

import globalConst from "../common/globalConst";
var global = globalConst.GlobalConst;

import lgxcom from '../common/common.js'
class RotateEngine extends absanimateengine.AbsAnimateEngine {
    constructor(graph) {
        super(graph);
        this.type = "rotate";
        this.rotAxisLen = -1;
    }
    animate() {
        if (!this.path) {
            return;
        }
        console.log("rotateengine------------------------");
        let result = this.path.animate(this.speed);
        if (this.rotAxisLen < 0) {
            let cntPt = this.getDstGraph().getZone().getCnt();
            this.rotAxisLen = funcs.distancePoint(result.rotPt, cntPt, 1);
        }
        let graphList = [];
        graphList.push(this.destGraph);
        rotategraphsvc.RotateGraphSvc.rotate(result.rotPt, result.angle, graphList, 1);

        let newCntPt = this.getDstGraph().getZone().getCnt();
        let dis = funcs.distancePoint(result.rotPt, newCntPt, 1);
        if (dis > global.ZERO_8E) {
            let vector = new lgxcom.LGXVector();
            vector.setBy2Pt(result.rotPt, newCntPt);
            let x = result.rotPt.x + vector.m * this.rotAxisLen;
            let y = result.rotPt.y + vector.n * this.rotAxisLen;
            this.destGraph.translate2DstPt({ x, y }, 1);
        }
    }
}

export default { RotateEngine }